//用来完成从输入读取两个数进行运算

import java.util.Scanner;

public class exceptionTest {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.next();
        String opStr = scanner.next();
        String str2 = scanner.next();
        scanner.close();
        System.out.println(calculate(str1, opStr, str2));
    }

    public static int calculate(String str1, String opStr, String str2) {
        int result = 0;
        try {
            int num1 = Integer.parseInt(str1);
            int num2 = Integer.parseInt(str2);
            char op = opStr.charAt(0);
            switch (op) {
                case '+':
                    result = num1 + num2;
                    break;
                case '-':
                    result = num1 - num2;
                    break;
                case '*':
                    result = num1 * num2;
                    break;
                case '/':
                    result = num1 / num2;
                    break;
                default:
                    //如果运算符不合法，首先抛出运行时异常，然后执行finally子句
                    throw new RuntimeException("Invalid expression");
            }
            return result;
        }
        //数字格式异常
        catch (NumberFormatException ex) {
            System.out.println("NumberFormatException");
        }
        //算术运算异常，比如1/0
        catch (ArithmeticException ex) {
            System.out.println("ArithmeticException");
        }
        //上面两个异常都是Exception的子类，最大的父类异常catch块要放在最后，否则编译无法通过
        catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        //finally子句一定会执行，不管是否抛出异常，在return前执行
        finally {
            System.out.println("The finally block");
        }
        return result;
    }
}
